/**
 * 将正常的list<dto> 根据dto中的某个值转换成级联形式 list<list<dto>>
 * @param data
 * @param sign
 */
export const dataTranferToCascade = function (data,sign,labelname) {
  let array = []
  for (let index in data){
    let existflag = false
    let dto = data[index]
    for (let arrayindex in array) {
      let i = array[arrayindex]
      if (i.id === dto[sign]) {
        i.children.push(dto)
        existflag = true
        break
      }
    }
    if (!existflag){
      let obj = {
        id:'',
        name:'',
        children:[],
        value:'',
        label:'',
      }
      obj.id = dto[sign]
      obj.name = dto[labelname]
      obj.children.push(dto)
      array.push(obj)
    }
  }
  return array
}

/**
 * 根据对arr中 obj 的一个属性 去重
 * @param arr
 * @param objkey
 * @returns {Array}
 */


export  const arrObjectDistinct = function (arr,objkey){ // 根据对arr中 obj 的一个属性 去重
  let existkey = {}
  let newarr = []
  for(let i in arr){

    if (!existkey[arr[i][objkey]]){
      existkey[[arr[i][objkey]]] = true
      newarr.push(arr[i])
    }
  }
  return newarr;

}


// let  arr = [
//   {zid:1,name:"haha",other:"dfdfdf"},
//   {zid:1,name:"haha",other:"dfdfdf"},
//   {zid:1,name:"haha",other:"dfdfdf"},
//   {zid:2,name:"hahe",other:"ddffdfdf"},
//   {zid:1,name:"haha",other:"dfddffdf"},
//   {zid:2,name:"hahe",other:"dfdfdgggf"},
//
// ]
//
// console.log(JSON.stringify(arr))
//
// //dataTranferToCascade(arr,"zid","name")
// console.log(JSON.stringify(dataTranferToCascade(arr,"zid","name")))
//
//


